//
//  UIBarButtonItem+Extension.swift
//  weiBo
//
//  Created by 杨雷 on 2016/12/1.
//  Copyright © 2016年 Yang.L. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    //便利构造函数
    convenience init(title: String, imageName: String? = nil, target: Any?, action: Selector) {
        
        self.init()
        
        //设置导航栏上的按钮
        let btn = UIButton()
        
        if imageName != nil {
            
            //如果有图标设置图片
            btn.setImage(UIImage(named: imageName!), for: .normal)
        }
        //设置按钮文字
        btn.setTitle(title, for: UIControlState.normal)
        //文字大小
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        //普通状态下按钮的颜色
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        //高亮颜色
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        //按钮大小
        btn.sizeToFit()
        
        //添加点击事件
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        //关联
        self.customView = btn
        
    }
    
}








